package org.rcloud.io.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.Blind_dateMapper;
import org.rcloud.io.model.Blind_date;
import org.rcloud.io.model.Endorsement;
import org.rcloud.io.service.Blind_dateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/3/4.
 */
@Service(value = "Blind_dateService")
public class Blind_dateServiceImpl implements Blind_dateService {

    @Autowired
    private Blind_dateMapper blind_dateMapper;

    @Override
    public ResultVo deleteByPrimaryKey(String id) {

        if (id.equals("") || id == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                blind_dateMapper.deleteByPrimaryKey(id);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo insert(Blind_date record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                blind_dateMapper.insert(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo insertSelective(Blind_date record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = blind_dateMapper.insertSelective(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Blind_date> selectByPrimaryKey(Blind_date id) {

        if (id.equals("") || id == null){
            return PageVo.setError("传入数据为空");
        } else {
            try {
                List<Blind_date> list = blind_dateMapper.selectByPrimaryKey(id);
                return PageVo.setOk(list);
            } catch (Exception e) {
                e.printStackTrace();
                return PageVo.setError(e.getMessage());
            }
        }

    }


    @Override
    public ResultVo updateByPrimaryKeySelective(Blind_date record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int update = blind_dateMapper.updateByPrimaryKeySelective(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo updateByPrimaryKey(Blind_date record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                blind_dateMapper.updateByPrimaryKey(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageInfo<Blind_date> selectByBlind_date(int pageNum,int pageSize,Map map){
        PageHelper.startPage(pageNum,pageSize,true);
        List<Blind_date> blind_dateList = blind_dateMapper.selectByBlind_date(map);
        PageInfo<Blind_date> pageInfo = new PageInfo<>(blind_dateList);
        return pageInfo;
    }

    @Override
    public ResultVo selectByKey(Blind_date record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Blind_date blind_date = blind_dateMapper.selectByKey(record);
                return ResultVo.setOK(blind_date);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Blind_date> selectAll() {

        try {
            List<Blind_date> list = blind_dateMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo selectBytime(String createtime) {

        if (createtime.equals("") || createtime == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Integer integer = blind_dateMapper.selectBytime(createtime);
                return ResultVo.setOK(integer);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
}

    @Override
    public ResultVo selectByNamedq(String createtime) {

        if (createtime.equals("") || createtime == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Integer integer = blind_dateMapper.selectByNamedq(createtime);
                return ResultVo.setOK(integer);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo selectByNamews(String createtime) {

        if (createtime.equals("") || createtime == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = blind_dateMapper.selectByNamews(createtime);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo selectByNamexd(String createtime) {

        if (createtime.equals("") || createtime == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = blind_dateMapper.selectByNamexd(createtime);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo selectByNamexk(String createtime) {

        if (createtime.equals("") || createtime == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = blind_dateMapper.selectByNamexk(createtime);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Blind_date> selectAllDQ() {

        try {
            List<Blind_date> list = blind_dateMapper.selectAllDQ();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public PageVo<Blind_date> selectAllWS() {

        try {
            List<Blind_date> list = blind_dateMapper.selectAllWS();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public PageVo<Blind_date> selectAllXD() {

        try {
            List<Blind_date> list = blind_dateMapper.selectAllXD();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public PageVo<Blind_date> selectAllXK() {

        try {
            List<Blind_date> list = blind_dateMapper.selectAllXK();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo addCertificate(Blind_date blindDate) {
        if (blindDate.equals("") || blindDate == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = blind_dateMapper.addMapping(blindDate);
                if (i > 0) {
                    return ResultVo.setOK("i");
                } else {
                    return ResultVo.setError("失败");
                }
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

   /* @Override
    public ResultVo delCertificate(Blind_date blindDate) {
        if (blindDate.equals("") || blindDate != null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = blind_dateMapper.delMapping(blindDate);
                if (i > 0) {
                    return ResultVo.setOK("i");
                } else {
                    return ResultVo.setError("删除证书未成功");
                }
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }*/

    @Override
    public PageInfo<Blind_date> selectNo(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Blind_date> list = null;
        try {
            list = blind_dateMapper.selectNo();
            if (list != null && !list.equals("")) {
                PageInfo<Blind_date> pageInfo = new PageInfo<>(list);
                return pageInfo;
            } else {
                return new PageInfo<>();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new PageInfo<>();
        }

    }

    @Override
    public PageInfo<Blind_date> selectYes(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize,true);
        List<Blind_date> list = null;
        try {
            list = blind_dateMapper.selectYes();
            if (list != null && !list.equals("")) {
                PageInfo<Blind_date> pageInfo = new PageInfo<>(list);
                return pageInfo;
            } else {
                return new PageInfo<>();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new PageInfo<>();
        }
    }

    @Override
    public PageVo<Blind_date> selectLike(String enname) {
        List<Blind_date> list = null;
        try {

            String s = enname;
            enname = "%" + s + "%";

            list = blind_dateMapper.selectLikeEnname(enname);
            if (list != null && !list.equals("")) {
                return PageVo.setOk(list);
            } else {
                return PageVo.setError("查询数据为空");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

}
